#pragma once

#include "ColligereMainFrame.hpp"

//! This class represents the application itself.
class ColligereApp : public wxApp
{
public:
	/*! @brief Default constructor.
	 *
	 * Sets the app name and vendor. Other initialization is done in 
	 * the function OnInit().
	 *
	 * @see ColligereApp::OnInit
	 **/
	ColligereApp();
	virtual ~ColligereApp();
	//! Returns a pointer to the the app's main frame.
	col::MainFrame *GetFrame();

	/*! @brief Returns a string containing the app. version string.
	 *
	 * The version string is in the form of "Colligere vX.XX" in release
	 * builds and "Colligere vX.XX DEBUG" in debug builds.
	 **/
	const wxString GetVersioString() const;

	//! Returns the dir from which the app was started.
	const wxString GetAppDir() const;
	//! Returns the root data dir.
	const wxString GetDataDir() const;
	//! Returns the root image dir.
	const wxString GetImageDir() const;
	//! Returns the XRC dir.
	const wxString GetXrcDir() const;
	//! Returns an absolute path to the apps temporary directory.
	const wxString GetTempDir() const;
	//! Returns an absolute path to the language directory.
	const wxString GetLanguageDir() const;

	/*! @brief Exits the application.
	 *
	 * Exits the application if the user didn't cancel the action (or 
	 * if Colligere isn't set to ask before exiting).
	 * 
	 * @return false if the user cancelled the operation, otherwise
	 *         the main frame will be destroyed and the process will
	 *         get terminated.
	 **/
	bool ExitApp();

    //! Icon indexes enum wrapper.
    struct IconIndex
    {
        enum
        {
            InvalidIndex = 0,
            Cd,
            Configure,
            EditAdd, EditCopy, EditPaste, EditRemove, EditUpdate,
            Exit,
            Search,
            FileClose, FileNew, FileOpen, FileSave, FileSaveAs,
			FlagUs, FlagFi,
            FolderClosed, FolderOpened,
            Help,
            Log,
            TrashcanEmpty, TrashcanFull,
            Vinyl
        };
	};

	wxBitmap GetIcon ( wxUint32 index ) const;
private:
	//! Loads all XRC resource files.
	void LoadResources() const;

	//! Initializes directoy locations.
	void InitializeDirectories();

	//! Loads all icons.
	void LoadIcons();

	void LoadIcon ( wxUint32 idx, const wxString &rPath );

	/*! @brief Overrides wxApp::OnInit()
	 *
	 * @return True on success (app. starts), false otherwise (app. aborts).
	 **/
	bool OnInit();
	int OnRun();
	void OnUnhandledException();
    void OnInitCmdLine ( wxCmdLineParser &Parser );
    bool OnCmdLineParsed ( wxCmdLineParser &rParser ); 
	/*! @brief Overrides wxApp::OnExit().
	 *
	 * @return Same as wxApp::OnExit().
	 **/
	int OnExit();
	
	//! Catches TABs to handle them correctly.
	void OnChar ( wxKeyEvent &rEvent );

	//! The main frame instance.
	col::MainFrame *mpFrame;

	wxFileName mAppDir, mDataDir, mImageDir, mXrcDir, mTempDir, mLangDir;
	
	wxSingleInstanceChecker *mpSingleChecker;

	//! The command line input file (if any)
	wxString mCmdLineInputFile;

	typedef std::map < wxUint32, wxBitmap > IconMap;
	IconMap mIcons;

	wxLocale mLocale;
};

DECLARE_APP ( ColligereApp );